package nl.rainbowsheep.reisorg.empl.site.service;

import java.util.ArrayList;
import java.util.List;
import nl.rainbowsheep.reisorg.empl.site.authentication.BasicAuthInterceptor;
import nl.rainbowsheep.reisorg.empl.site.model.BurritoUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class UserService {

    @Value("${api.url}")
    String url;

    public BurritoUser saveUser(BurritoUser user) {
        RestTemplate template = new RestTemplate();
        final List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
        interceptors.add(new BasicAuthInterceptor());
        template.setInterceptors(interceptors);

        return template.postForObject(url + "user/save", user, BurritoUser.class);
    }
}
